package com.lyd.sweet.mybatis.mapper;

import org.apache.ibatis.mapping.MappedStatement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tk.mybatis.mapper.mapperhelper.MapperHelper;
import tk.mybatis.mapper.mapperhelper.MapperTemplate;
import tk.mybatis.mapper.mapperhelper.SqlHelper;

/**
 * 类的用途
 *
 * @author 木木
 **/
public class UpdateProvider extends MapperTemplate {

    private Logger logger = LoggerFactory.getLogger(UpdateProvider.class);

    public UpdateProvider(Class<?> mapperClass, MapperHelper mapperHelper) {
        super(mapperClass, mapperHelper);
    }


    public String updateByOneField(MappedStatement ms) {
        Class<?> entityClass = getEntityClass(ms);
        StringBuilder sql = new StringBuilder();
        sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass)));
        sql.append(" <set>");
        sql.append("${field} = #{value}");
        sql.append(" </set> ");
        sql.append("<where>");
        sql.append("<if test=\"wField != null\" >");
        sql.append("and ${wField}=#{wValue}");
        sql.append("</if>");
        sql.append("</where>");
        return sql.toString();
    }


}
